﻿using EmgrMvc.BLL;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;

namespace EmgrMvc.Models
{
    public class AppJob : IJob
    {
        public MyContext Db { get; set; } //这些属性必须大写开头，有点坑
        public bool IsGroup { get; set; }
        public int GroupId { get; set; }
        public bool IsEven { get; set; }
        public string Action { get; set; }
        public Task Execute(IJobExecutionContext context)
        {
            return Task.Factory.StartNew(() =>
            {
                Console.WriteLine($"Executing Job:\nIsGroup: {IsGroup}, GroupId: {GroupId}, IsEven: {IsEven}, Action: {Action}");
                EsysBLL bll = new EsysBLL(Db);
                if (Action == "ON")
                {
                    if (IsGroup)
                        bll.PowerOnByGroup(GroupId);
                    else
                        bll.PowerOnDevice(GroupId);
                }
                else
                {
                    if (IsGroup)
                        bll.PowerOffByGroup(GroupId);
                    else
                        bll.PowerOffDevice(GroupId);
                }
                //Console.WriteLine($"Hello {UserName}!");
            });
        }
    }
}
